package com.westos.service;

import com.westos.dao.UserDao;
import com.westos.domain.User;
import com.westos.utils.UUIDUtils;

/**
 * @Author: ShenMouMou
 * @CreateTime: 2019-12-27 10:13
 * @Company:西部开源教育科技有限公司
 * @Description:爱生活，爱Java!
 */
public class UserService {

    private UserDao dao;


    //注册用户
    public boolean registerUser(User user) throws Exception {
        user.setUid(UUIDUtils.getUUID());
        //调用dao来注册

        boolean b = getDao().findUsername(user.getUsername());
        if (b) {
            getDao().registerUser(user);
        }
        return b;
    }
    public User login(User user) throws Exception {
        //调用dao
        User user1 = getDao().login(user);
        return user1;
    }


    public UserDao getDao() {
        if(this.dao==null){
            this.dao=new UserDao();
        }
        return dao;
    }

    public void setDao(UserDao dao) {
        this.dao = dao;
    }
}
